package com.hh.admin.model.newinfo.service;

import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.hh.admin.model.newinfo.form.NewInfoForm;
import com.hh.admin.model.newinfo.form.ParamNewInfoBean;
import com.hh.admin.model.newinfo.form.ResultNewInfoBean;
import com.hh.common.ibatis.dao.IQueryDao;
import com.hh.common.ibatis.dao.IUpdateDao;

/**
 * 新鲜资讯Service
 * @author 冯昌硕
 * @create 2013-1-20 下午2:41:44
 */
public class NewInfoService {

    private static final Logger log = Logger.getLogger(NewInfoService.class);

    private IQueryDao queryDao;
    
    private IUpdateDao updateDao;
    
    /**
     * 新增新鲜资讯内容记录
     * @param form 表单Form
     * @return
     * @throws SQLException
     * @create 2013-1-20 下午8:13:33
     */
    public int insertNewInfo(NewInfoForm form) throws SQLException {
        ParamNewInfoBean paramBean = new ParamNewInfoBean();
        paramBean.setTitle(form.getTitle());
        paramBean.setDetailContent(form.getDetailContent());
        paramBean.setCreateUser(form.getCreateUser());
        paramBean.setStatus(form.getStatus());
        
        log.debug("新增新鲜资讯信息 paramBean=[" + paramBean + "]");
        return (Integer) updateDao.insert("newinfo.insertNewInfo", paramBean);
    }
    
    /**
     * 删除新鲜资讯内容记录
     * @param id 要删除的记录ID
     * @return
     * @throws SQLException
     * @create 2013-1-20 下午8:25:32
     */
    public int deleteOneNewInfo(int id) throws SQLException {
        return updateDao.delete("newinfo.deleteNewInfo", id);
    }
    
    /**
     * 批量删除新鲜资讯记录
     * @param ids 要删除的新鲜资讯ID
     * @return
     * @throws SQLException
     * @create 2013-1-20 下午8:28:00
     */
    public int deleteManyNewInfo(Integer[] ids) throws SQLException {
        return updateDao.batchDelete("newinfo.deleteNewInfo", ids);
    }
    
    /**
     * 获取新鲜资讯记录详情
     * @param id 新鲜资讯ID
     * @return 新鲜资讯详情
     * @throws ClassCastException
     * @throws SQLException
     * @create 2013-1-20 下午9:01:27
     */
    public ResultNewInfoBean getNewInfoDetail(int id) throws ClassCastException, SQLException {
        return queryDao.queryForObject("newinfo.selNewInfoDetail", id, ResultNewInfoBean.class);
    }
    
    /**
     * 更新新鲜资讯信息
     * @param form 表单项
     * @return
     * @throws SQLException
     * @create 2013-1-20 下午10:32:42
     */
    public int updateNewInfo(NewInfoForm form) throws SQLException {
        ParamNewInfoBean paramBean = new ParamNewInfoBean();
        paramBean.setTitle(form.getTitle());
        paramBean.setDetailContent(form.getDetailContent());
        paramBean.setStatus(form.getStatus());
        paramBean.setId(form.getId());
        
        log.debug("更新新鲜资讯信息 paramBean=[" + paramBean + "]");
        return updateDao.update("newinfo.undateNewInfo", paramBean);
    }

    public void setQueryDao(IQueryDao queryDao) {
        this.queryDao = queryDao;
    }

    public void setUpdateDao(IUpdateDao updateDao) {
        this.updateDao = updateDao;
    }
    
}
